FAQ汇萃 >> Tomcat >> 为什么在 Response.addCookie() 调用 Response.sendRedirect() 总是出错,这是不是TOMCAT的BUG? [查看别人的评论]

由 webmaster 发布于: 2001-01-30 10:07

Talking

Yes, there is a bug in Tomcat 3.1 (and possibly other servlet engines). To send a cookie through a redirect, you must set the headers manually. seanm@narus.com suggests:
Cookie long_term = new Cookie(LONG_TERM_COOKIE_NAME, user_name);
long_term.setMaxAge(60*60*24*4);
long_term.setPath("/Blah");
response.addCookie(long_term);

response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location",REDIRECT_PAGE);

点这里对该文章发表评论

该文章总得分是 0 分,你认为它对你有帮助吗? [非常多](0) [有一些](0) [无帮助](0) [是灌水](0)

Copyright © 2001 - 2009 JSP001.com . All Rights Reserved